from http import HTTPStatus

from infirmary_admin_src.infirmary_common.infirmary_errors.enums import SnowySystemResultEnum


class SnowySystemException(Exception):
    code = HTTPStatus.BAD_GATEWAY
    error_code = HTTPStatus.BAD_REQUEST
    msg = HTTPStatus.BAD_GATEWAY.description

    def __init__(self, result: SnowySystemResultEnum = None, code: str = "00000", msg: str = "系统运行错误"):
        if result:
            self.code = result.value[0] or code
            self.msg = result.value[1] or msg
        else:
            self.code = code
            self.msg = msg
        super().__init__(self)

    def __str__(self):
        return '[%s]%s' % (self.code, self.msg)

    def __repr__(self):
        return '[%s]%s' % (self.code, self.msg)


class SnowyBusinessException(SnowySystemException):
    def __init__(self, result: SnowySystemResultEnum = None, error_code=None, code: str = "00000",
                 msg: str = "业务逻辑错误"):
        super().__init__(result, code, msg)
        self.error_code = error_code or self.error_code
